package com.glodon.paas.job.agent;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.log4j.MDC;

import com.glodon.paas.job.agent.mq.JmsAgent;
import com.glodon.paas.job.agent.worker.WorkerConfig;

public class Main {
	public static void main(String[] args) throws UnknownHostException {
		MDC.put("ip", InetAddress.getLocalHost().getHostAddress());
		JmsAgent jmsAgent = new JmsAgent();
		String[] types = { "profile", "timeout", "gcl10-calc", "gcl10-merge", "rvt", "doc" };
		String[] cmds = { "profile", "timeout", "GCLCloudCalculator", "GCLMergeQty", "RevitWorker",
				"java com.glodon.worker.docconverter.Main" };
		if (jmsAgent.getWorkerConfigs() == null) jmsAgent.setWorkerConfigs(initWorkerConfigs(types, cmds));
		jmsAgent.start();
		System.out.println("agent started");
	}

	private static WorkerConfig[] initWorkerConfigs(String[] types, String[] cmds) {
		WorkerConfig[] workerConfigs = new WorkerConfig[types.length];
		for (int i = 0; i < types.length; i++) {
			String type = types[i];
			workerConfigs[i] = new WorkerConfig(type, cmds[i]);
		}
		return workerConfigs;
	}
}
